#include "RetryManager.h"

bool RetryManager::retryOperationNonBlocking(std::function<bool()> operation, const char* errorMsg, int retryCount, unsigned long interval) {
    if (millis() - lastRetryTime >= interval) {
        if (operation()) {
            currentRetry = 0;
            return true;
        }
        debugLog("%s, retrying (%d/%d)...\n", errorMsg, currentRetry + 1, retryCount);
        currentRetry++;
        lastRetryTime = millis();
    }

    if (currentRetry >= retryCount) {
        debugLog("%s after %d retries\n", errorMsg, retryCount);
        currentRetry = 0;
        return false;
    }

    return false;
}

RetryManager retryManager;